package SIM_settings;
require Exporter;
use strict;

# Settings module for shared perl settings.
our @ISA        = ("Exporter");
our @EXPORT     = qw(
                     $SIM_MonDevices $SIM_CiscoPwds $SIM_TftpBootDir
		     $SIM_beep $SIM_History $manDomain
		     $httpScriptName $remoteUser $ipDatabaseDir $macDatabaseDir $logDir $simPtrDir $sharedConfDir $graphDir
		     $switchInfoDir $deviceDir $oidHelpDir $sipmanStarter
		     $snmpStrings $inaddrSrvList $dnsCache $baseDomain $confRrdTool $searchIndexFile
                     %errorColor %errorAllert %SIMparam
                    );
our @VERSION    = 0.01;                 # version number


our $switchInfoDir = "test";
$manDomain = $ENV{'SIM_MANDOMAIN'};
our %SIMparam = ();
$SIMparam{'SIMbaseDir'} = $ENV{'SIM_BASEDIR'} || die "Oops no env found for SIM_BASEDIR.";
$SIMparam{'SIMmainDir'} = "$SIMparam{'SIMbaseDir'}/main";
$SIMparam{'SIMmainConfigDir'} = "$SIMparam{'SIMmainDir'}/configs";
$SIMparam{'SIMsharedDir'} = "$SIMparam{'SIMbaseDir'}/shared";
$SIMparam{'SIMsharedConfDir'} = "$SIMparam{'SIMsharedDir'}/configs";
$SIMparam{'SIMdataDir'} = "$SIMparam{'SIMbaseDir'}/data/$manDomain";
$SIMparam{'SIMdataConfDir'} = "$SIMparam{'SIMdataDir'}/configs";
$SIMparam{'SIMipDatabase'} = "$SIMparam{'SIMdataDir'}/ip-database";
$SIMparam{'SIMtmpDir'} = "$SIMparam{'SIMdataDir'}/tmp";

print("SIMtmpDir=$SIMparam{'SIMtmpDir'}\n");

my @fileList = ();
push @fileList, "$SIMparam{'SIMdataConfDir'}/settings2.conf\n";
foreach my $entry (@fileList) {
  chomp($entry);
  open( CONF, $entry );
  my @fileContent = <CONF>;
  foreach my $line (@fileContent) {
    chomp($line);
    my ( $varName, $varType, $varData ) = split(' ', $line, 3);
    if (( substr($varName,0,1) eq "#" ) or ( "$varName" eq "" )) {
      my $dummy;
    } elsif ( "$varType" eq "path" ) {
      my ( $basePath, $rest ) = split(' ', $varData);
      $SIMparam{$varName} = "$SIMparam{$basePath}/$rest";
#     print(" $varName=$SIMparam{$varName} ");
    } elsif ( "$varType" eq "var" ) {
      $SIMparam{$varName} = $varData;
    }
  }
}



# errorInfo
my $errInfoFile = "$sharedConfDir/errorTypes";
%errorColor;
%errorAllert;
if ( -r $errInfoFile ) {
  open( ERRINFO, $errInfoFile );
  my @lines = <ERRINFO>;
  foreach my $entry (@lines) {
    chomp $entry;
    my ( $test, $type, $color, $allert ) = split(' ', $entry);
    if ( "$test" eq "error" ) {
      $errorColor{$type} = $color;
      $errorAllert{$type} = $allert;
    }
  }
}


# Various references to external filenames.
$SIM_TftpBootDir = "$settingsDir/tftpBootDir";

$SIM_MonDevices = "$settingsDir/mon-devicelist";
$SIM_CiscoPwds = "$settingsDir/runCiscoTelnetPwds";
$SIM_History = "$settingsDir/testCmdHistory";
$SIM_beep = "/sipman3/sounds/BEEP1B.WAV";
# end.
1;

